problems with mmap on qemu-arm
I'm running qemu-arm and see the following output from mmap with 'strace qemu-arm -strace' (for both host and traget strace output):mmap(NULL, 32800, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ad329b46000
4023 mmap(0,131072,7,34,-1,0) = 0xfffffff2
When my program later tries to read memory at 0xfffffffe it fails with a SIGSEGV:
Program received signal SIGSEGV, Segmentation fault.
1: x/i $pc 0xce30: ldr r1, [r5]
(gdb) i r
r5 0xfffffffe -2
Why does qemu-arm return such high addresses on a 32 bit platform and why is the memory inaccessible? If this doesn't seem like an obvious bug in my code, where in the qemu code should I start looking for how mmap works?
Kai
--
Kai Backman, Software Engineer, [email protected]
I tracked this down to the code in linux-user/syscall.c. The mmap code seems broken, it assumes arg1 is a pointer to an array where the real arguments are. Given arg1 = 0 the memory access check fails.
The code I'm working on will happily take mmap2 instead so I have a workaround. Does someone have an opinion on the state of the mmap code?
Kai
Quoted 22 lines · Kai Backman
I'm running qemu-arm and see the following output from mmap with 'strace qemu-arm -strace' (for both host and traget strace output):
mmap(NULL, 32800, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)=0x2ad329b46000
4023mmap(0,131072,7,34,-1,0)=0xfffffff2When my program later tries to read memory at
0xfffffffeit fails with a SIGSEGV:
Program received signal SIGSEGV, Segmentation fault.
1: x/i $pc0xce30: ldr r1, [r5]
(gdb) i r
r50xfffffffe-2Why does qemu-arm return such high addresses on a 32 bit platform and why is the memory inaccessible? If this doesn't seem like an obvious bug in my code, where in the qemu code should I start looking for how mmap works?
Kai
--
Kai Backman, Software Engineer, [email protected]
Signature · 1 line
Kai Backman, Software Engineer, [email protected]
Quoted 6 lines · Kai Backman
I tracked this down to the code in
linux-user/syscall.c. The mmap code seems broken, it assumes arg1 is a pointer to an array where the real arguments are. Given arg1 = 0 the memory access check fails. The code I'm working on will happily take mmap2 instead so I have a workaround. Does someone have an opinion on the state of the mmap code? �Kai
looking at old_mmap() for arm in kernel, qemu seems to the right thing. Ie you are probably calling mmap the wrong way, you are supposed to give it a array.
mmap syscall is depreceated, glibc uses mmap2 since forever.
Quoted 30 lines · Kai Backman
I'm running qemu-arm and see the following output from mmap with 'strace qemu-arm -strace' (for both host and traget strace output):
mmap(NULL, 32800, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) =0x2ad329b46000
4023mmap(0,131072,7,34,-1,0)=0xfffffff2
When my program later tries to read memory at0xfffffffeit fails with a SIGSEGV:
Program received signal SIGSEGV, Segmentation fault.
1: x/i $pc �0xce30: � � ldr � � r1, [r5]
(gdb) i r
r5 � � � � � �0xfffffffe� � � -2
Why does qemu-arm return such high addresses on a 32 bit platform and why is the memory inaccessible? If this doesn't seem like an obvious bug in my code, where in the qemu code should I start looking for how mmap works?
�Kai
--
Kai Backman, Software Engineer, [2][email protected]--
Kai Backman, Software Engineer, [3][email protected]References
Visible links
1. mailto:[email protected]
2. mailto:[email protected]
3. mailto:[email protected]